package campus.controller;

import campus.model.Account;
import campus.model.AccountExample;
import campus.model.Cash;
import campus.model.CashExample;
import campus.service.CashService;
import campus.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author M
 * @create 2020-05-08 0:18
 * @desc 现金日记账控制层
 **/
@RestController
@CrossOrigin
@RequestMapping("cash")
public class CashController {
    @Autowired
    private CashService cashService;

    /**
         * @Author M
         * @name 现金日记账列表
         * @Date 2:33 2020/5/9
     **/
    @RequestMapping(value = "/selectByExample",method = RequestMethod.GET)
    public List<Cash> selectByExample(CashExample example) {
        return cashService.selectByExample(null);
    }
   /**
        * @Author M
        * @name 现金日记账分页
        * @Date 2:34 2020/5/9
    **/
   @RequestMapping(value = "findByAllPageSize/{pageNum}/{pageSize}",method = RequestMethod.POST)
   public PageResult findByAllPageSize(@RequestBody Cash cash, @PathVariable("pageNum") int pageNum , @PathVariable("pageSize") int pageSize){
       if(cash.getcCdate() != null){
           SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           String strDate = format.format(cash.getcCdate());
           cash.setCdate(strDate);
       }
       PageResult byAllPageSize = cashService.findByAllPageSize(cash,pageNum, pageSize);
       return byAllPageSize;
   }

    @RequestMapping(value = "findByAllPageSize2/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public PageResult findByAllPageSize2(@RequestBody Cash cash, @PathVariable("pageNum") int pageNum , @PathVariable("pageSize") int pageSize){
        if(cash.getcCdate() != null){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String strDate = format.format(cash.getcCdate());
            cash.setCdate(strDate);
        }
        PageResult byAllPageSize = cashService.findByAllPageSize2(cash,pageNum, pageSize);
        return byAllPageSize;
    }

    /**
        * @Author M
        * @name 现金日记账主键删除
        * @Date 20:38 2020/5/9
    **/
    @RequestMapping(value = "/delete/{cId}",method = RequestMethod.DELETE)
    public int deleteByPrimaryKey(@PathVariable(value = "cId") Integer cId) {
        return cashService.deleteByPrimaryKey(cId);
    }

    /**
         * @Author M
         * @name 批量删除
         * @Date 20:38 2020/5/9
     **/

    @RequestMapping(value = "plscs/{ids}",method = RequestMethod.GET)
    public int plscs(@PathVariable(value = "ids") int[] ids){
      return cashService.plscs(ids);
    }


}
